Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Accessing class data members

You can directly access data members from within the class where they are defined by using the data member name anywhere you can use a variable. This includes all data members defined directly within the class definition and all PUBLIC and PROTECTED data members defined in any super class of the class hierarchy.

You can access PUBLIC data members from outside the class hierarchy of a given object where they are defined by using an object reference to qualify the data member name. There is no direct access to PRIVATE or PROTECTED data members from outside the class hierarchy. Also, note that only variables can be PUBLIC. Therefore, if you want to expose a non-variable (such as a buffer, temp-table, query, or ProDataSet) to other classes, you must do so using one of these mechanisms:

Thus, non-public data members support the object-oriented design paradigm of encapsulating data with the object interface and not exposing it to external agents directly.

This is the syntax for referencing a PUBLIC data member from outside the object where it is defined:

Syntax
object-reference:data-member-name 

Element descriptions for this syntax diagram follow:

object-reference

An object reference to a class or super class where the PUBLIC data member is defined.

data-member-name

The name of a PUBLIC data member defined somewhere in the class hierarchy of object-reference.

The following code from the Main sample class shows how you can access a PUBLIC data member from outside the class instance (acme.myObjs.CustObj) where it is defined:

CLASS Main: 
    DEFINE PRIVATE VARIABLE rCustObj  
        AS CLASS acme.myObjs.CustObj NO-UNDO. ... 
    DEFINE PRIVATE VARIABLE rHelperClass 
        AS CLASS acme.myObjs.Common.HelperClass NO-UNDO. 
     
    CONSTRUCTOR PUBLIC Main( ): 
        /* Create an instance of the HelperClass class */ 
        rHelperClass = NEW acme.myObjs.Common.HelperClass( ). 
        /* Create an instance of the CustObj class */ 
        rCustObj = NEW acme.myObjs.CustObj( ). 
    END CONSTRUCTOR. 
    METHOD PUBLIC VOID ObjectInfo( ): 
        rHelperClass:ListDate(INPUT rCustObj). 
        MESSAGE rCustObj:timestamp.  
        ... 
    END METHOD. 
    ... 
END CLASS. 

In the previous example, timestamp is a PUBLIC data member defined in a super class (acme.myObjs.Common.CommonObj) of the object referenced by rCustObj.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095